<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class peng extends CI_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->library('form_validation');
	}

	public function index(){
		$this->load->model('pengiriman','',true);
		$data['pengiriman'] = $this->pengiriman->get_list();
		$id_kirim=$this->pengiriman->maks_pengiriman()->row()->maksid+1;
		$data['nomer_pengiriman'] = "peng_bw_".$id_kirim;
		$data['pesanan'] = $this->pengiriman->get_pesanan();
		$data['karyawan'] = $this->pengiriman->get_karyawan();
		
		
		
		$this->load->view('header');
		$this->load->view('menu');
		$this->load->view('pengiriman',$data);
		$this->load->view('footer');
	}

	public function insert(){
	$this->load->model('pengiriman','',true);
	$id_kirim=$this->pengiriman->maks_pengiriman()->row()->maksid+1;
		$data = array(
				'id_pengiriman' 		=> $id_kirim,
				'no_pengiriman' 		=> $this->input->post('no_pengiriman'),
				'nomer_pesanan' 		=> $this->input->post('nomer_pesanan'),
				'karyawan' 		=> $this->input->post('karyawan'),
				'tanggal' 				=> date('d-m-Y'),
				'status'				=> 0,
				
			);
			
			
			$data1 = array(
				'status_pesanan' 			=> '2'
				
			);
		$this->pengiriman->updatePesanan($this->input->post('nomer_pesanan'),$data1);
			
			
			
		$this->pengiriman->insert($data);
			redirect('peng');
	}

	public function delete($data){
		$this->load->model('pengiriman','',true);
		$this->pengiriman->delete($data);
		redirect('akv');
	}

	public function edit($id){
		$this->load->model('pengiriman','',true);
		$data['detail'] = $this->pengiriman->get_by_id($id);
		$data['pengiriman'] = $this->pengiriman->get_all();
		$this->load->view('header');
		$this->load->view('menu');
		$this->load->view('pengiriman',$data);
		$this->load->view('footer');
	}
	public function update(){
		$datainput = array(
				'no_pengiriman' 		=> $this->input->post('no_pengiriman'),
				'nomer_pesanan' 		=> $this->input->post('nomer_pesanan'),
				'nama' 					=> $this->input->post('nama'),
				'alamat'				=> $this->input->post('alamat'),
				'karyawan'			=> $this->input->post('karyawan'),
				'jenis_barang'			=> $this->input->post('kode_barang'),
				'kuantitas'				=> $this->input->post('jumlah')
			);
			
			
			
			
		$id = $this->input->post('id_pengiriman');
		//var_dump($id );
		//return;
		
		$this->load->model('pengiriman','',true);
		//$this->form_validation->set_rules('nama', 'nama', 'trim|required|is_unique[pengiriman.nama]');
		if ($this->form_validation->run() == FALSE) {
			$menu['error'] = true;
			$this->load->model('pengiriman','',true);
			$data['pengiriman'] = $this->pengiriman->get_all();
			$this->load->view('header');
			$this->load->view('menu');
			$this->load->view('pengiriman',$data);
			$this->load->view('footer');
		} else {
			$this->pengiriman->update($id,$data);
			redirect('peng');
		}
		$this->pengiriman->update($id,$datainput);
			redirect('peng');
	}
}